#include<algorithm>
#include<cstdio>
#include<vector>
#include<string.h>
using namespace std;
int main(){
    //freopen("in.txt","r",stdin);
    int N;
    scanf("%d",&N);
    int inp[N];
    for(int i=0;i<N;i++){
        scanf("%d",&inp[i]);
    }
    int tmp[N];
    memcpy(tmp,inp,sizeof(inp));
    sort(tmp,tmp+N);
    vector<int>ans;
    int maxi=-1;
    for(int i=0;i<N;i++){
        if(inp[i]>maxi){maxi=inp[i];}
        if(tmp[i]==inp[i]&&tmp[i]==maxi){
            ans.push_back(inp[i]);
        }
    }
    printf("%d\n",ans.size());
    if(ans.size()>0){
        printf("%d",ans[0]);
        for(int i=1;i<ans.size();i++){
            printf(" %d",ans[i]);
        }
        printf("\n");
        return 0;
    }
    else{
        printf("\n");
        return 0;
    }
}
